'use strict';

const path = require('path');
const fs = require('fs');

const FileLogWriter = require('../log/fs_log_writer');

class LogUtil {
  /**
   * 得到一个文件日志Writer
   * @param {String} loggerName 日志名称，用于日志文件名中
   * @param {String} prefix 日志前缀，用户区分同类日志文件
   * @return {FileLogWriter} FileLogWriter
   */
  static getFileLogWriter(loggerName, prefix = '') {
    const logPath = path.join(__dirname, '../../logs/');
    if (!fs.existsSync(logPath)) {
      fs.mkdirSync(logPath);
    }
    return new FileLogWriter(path.normalize(path.join(logPath, `${prefix}.${loggerName}.log`)));
  }
}

module.exports = LogUtil;
